//
//  DynamicDetailTableViewCell.m
//  结伴
//
//  Created by eliot on 16/8/10.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "DynamicDetailTableViewCell.h"

@implementation DynamicDetailTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(UILabel *)likePersonCount {
    if (!_likePersonCount) {
        _likePersonCount = [[UILabel alloc] init];
        [self addSubview:_likePersonCount];
        _likePersonCount.frame = CGRectMake(15, 15, Swidth - 30, 19);
        _likePersonCount.textColor = nineColor;
        _likePersonCount.font = [UIFont systemFontOfSize:16];
    }
    return _likePersonCount;

}

-(UIScrollView *)mySc {
    if (!_mySc) {
        _mySc = [[UIScrollView alloc]init];
        _mySc.delegate = self;
        [self addSubview:_mySc];
        _mySc.frame = CGRectMake(15, 40, Swidth - 25, 40);
    }
    return _mySc;
}

- (void)setUpCellWithDictionary:(NSDictionary *)dic {
    _likePersonCount.text = [NSString stringWithFormat:@"喜欢(%@人)", dic[@"count"]];
    NSArray *imgArr = dic[@"img"];
    self.mySc.pagingEnabled = YES;
    CGFloat width = 25;
    CGFloat height = width;
    NSInteger rowNum = _mySc.frame.size.width / 35;
    if (rowNum <= imgArr.count) {
        
    }else {
        rowNum = imgArr.count;
    }
    CGFloat offsetX = 10;
    CGFloat y = (_mySc.frame.size.height - 25) / 2.0;
    CGFloat x = offsetX;
    //填充滑动视图内容
    UIView *lastView = nil;
    for (int i = 0; i<= rowNum - 1; i++) {
        CGRect rect ;
        if (i == 0) {
            rect.origin.x = 0;
        }else {
            rect.origin.x = x;
        }
        
        rect.origin.y = y;
        rect.size.width = width;
        rect.size.height = height;
       

       
        
        
        if (i == rowNum - 1) {
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(lastView.frame.origin.x + offsetX + width, y, width, height);
            [btn setImage:[UIImage imageNamed:@"nav_more_pre"] forState:UIControlStateNormal];
            btn.layer.borderWidth = 1;
            btn.layer.borderColor = [[UIColor colorWithRed:205/255.0 green:205/255.0 blue:205/255.0 alpha:1.0f] CGColor];
            [btn addTarget:self action:@selector(checkMore) forControlEvents:UIControlEventTouchUpInside];
            [self.mySc addSubview:btn];
            btn.backgroundColor = [UIColor redColor];
            
            
        }else {
            NSString *imageDic = imgArr[i];
            
            //首先创建一个视图
            UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectZero];
            imageview.contentMode = UIViewContentModeScaleAspectFit;
            imageview.contentMode = UIViewContentModeScaleToFill;
            //为这个图片设置适当位置
            
            imageview.layer.cornerRadius = width / 2.0;
            imageview.layer.masksToBounds = YES;
            imageview.frame = rect;
            
            //确定下张图片开始的x坐标
            x += width + offsetX;
            lastView = imageview;
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickMemberHead:)];
            imageview.tag = i;
            [imageview addGestureRecognizer:tap];
            imageview.userInteractionEnabled = YES;
            //NSLog(@"i = %f, x = %f,  %f", offsetX, width,Swidth);
            
            
            
            //设置图片为背景
            //[imageview sd_setImageWithURL:[NSURL URLWithString:imageDic]];
            imageview.image = [UIImage imageNamed:imageDic];
            [self.mySc addSubview:imageview];
        }
     
        
    }
    
    //显示适当区域
    [self.mySc setContentSize:CGSizeMake(CGRectGetMaxX(lastView.frame) + offsetX*2 + width, 0)];

}

//点击点赞人的头像
- (void)clickMemberHead:(UITapGestureRecognizer *)tap {


}

//查看更多点赞的人
- (void)checkMore {


}


@end
